package com.colin.app.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.colin.app.app.AppApplication;
import com.colin.app.db.table.AdvertTable;

/**
 * Created by Administrator on 2017/5/23.
 */

public class MySQLiteHelper extends SQLiteOpenHelper {
    private static MySQLiteHelper mySQLiteOpener;
    private static final String SQLITE_NAME = "app.db";
    private static final int SQLITE_VERSION = 1;

    public static class Holder {
        static MySQLiteHelper instance = new MySQLiteHelper(AppApplication.getContext());
    }

    public static MySQLiteHelper getInstance() {
        return Holder.instance;
    }


    //  广告:根据广告ID创建
    private static final String CREATE_ADVERT_TABLE_SQL = "CREATE TABLE IF NOT EXISTS " + AdvertTable.TABLE_NAME
            + "("
            + AdvertTable.ADVERT_ID + " INTEGER PRIMARY KEY ,"
            + AdvertTable.ADVERT_TITLE + " TEXT,"
            + AdvertTable.ADVERT_URL + " TEXT,"
            + AdvertTable.ADVERT_IMAGEURL + " TEXT,"
            + AdvertTable.ADVERT_END + " TEXT,"
            + AdvertTable.ADVERT_SAVE_IMAGE_PATH + " TEXT,"
            + AdvertTable.ADVERT_GSON + " TEXT "
            + ");";

    private MySQLiteHelper(Context context) {
        super(context, SQLITE_NAME, null, SQLITE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_ADVERT_TABLE_SQL);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (newVersion != oldVersion) {
//            db.execSQL("DROP TABLE IF EXISTS " + HistoryDeviceInputTable.TABLE_NAME);
//            db.execSQL("DROP TABLE IF EXISTS " + CityTable.TABLE_NAME);
        }
    }
}
